from tkinter import *

class PopupMenu:
	def __init__(self):
		window = Tk()
		window.title("PopupMenu")


		frame0 = Frame(window)
		frame0.pack()
		Button(frame0, text = "Line",command = self.dLine).grid(row = 1,column = 1)
		Button(frame0, text = "Oval", command = self.dOval).grid(row = 1,column = 2)
		Button(frame0, text = "Rectangle", command = self.dRectangle).grid(row = 1,column = 3)
		Button(frame0, text = "Clear", command = self.clear).grid(row = 1,column = 4)

		self.menu = Menu(window, tearoff = 0)
		self.menu.add_command(label = "Draw the line", command = self.dLine)
		self.menu.add_command(label = "Draw the Oval", command = self.dOval)
		self.menu.add_command(label = "Draw the rectangle", command = self.dRectangle)
		self.menu.add_command(label = "Clear",command = self.clear)


		self.canvas = Canvas(window, width = 200, height = 200,bg = "white")
		self.canvas.pack()

		self.canvas.bind("<Button-3>",self.popup)



		window.mainloop()

	def popup(self,event):
		self.menu.post(event.x_root,event.y_root)

	def dLine(self):
		self.canvas.create_line(10,10,190,190, tags = "line")

	def dOval(self):
		self.canvas.create_oval(10,10,190,90, tags = "oval")

	def dRectangle(self):
		self.canvas.create_rectangle(10,10,80,80, tags = "rectangle")

	def clear(self):
		self.canvas.delete("line", "oval", "rectangle")


PopupMenu()
